﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Shrestha.Trigraph
{
    public sealed class History
    {
        private static History instance;
        private Stack<string> statementLog;
        private string currentStatement;

        private History()
        {
            statementLog = new Stack<string>();
            currentStatement = null;
        }

        public static History Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new History();
                }
                return instance;
            }
        }

        public void Write(string statement)
        {
            if (currentStatement != null)
            {
                statementLog.Push(currentStatement);
            }
            currentStatement = statement;            
        }

        public string Back()
        {
            string statement = null;
            if (statementLog.Count > 0)
            {
                statement = statementLog.Pop();
                //statementLog.Push(currentStatement);
                currentStatement = null;
            }
            return statement;
        }
    }
}
